#include <iostream>
#include <vector>
#include <Vector.hpp>
#include <algorithm>

using namespace std;

class Solution
{
public:
    vector<vector<int>> insert(vector<vector<int>> &intervals, vector<int> &newInterval)
    {
        vector<vector<int>> ans;
        bool first = true;
        for (auto i : intervals)
        {
            if (i[1] < newInterval[0])
            {
                ans.push_back(i);
            }
            else if (i[0] > newInterval[1])
            {
                if (first)
                {
                    ans.push_back(newInterval);
                    first = false;
                }
                ans.push_back(i);
            }
            else
            {
                newInterval[0] = min(i[0], newInterval[0]);
                newInterval[1] = max(i[1], newInterval[1]);
            }
        }
        if (first)
        {
            ans.push_back(newInterval);
        }
        return ans;
    }
};

int main()
{
    cout << "Code57" << endl;
    Solution s;
    vector<vector<int>> intervals = {{1, 3}, {6, 9}};
    vector<vector<int>> ans = s.insert(intervals, vector<int>{0, 11});
    Print2DVector(ans);
    return 0;
}